<%@page import="java.util.List"%>
<%@page import="mybatis.conService.ServiceFactory"%>
<%@page import="org.apache.ibatis.session.SqlSession"%>
<%@page import="vo.WinNumVO"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%
	SqlSession ss = ServiceFactory.getFactory().openSession();
	
	int winNumCount = ss.selectOne("winNumCount");
	if(winNumCount == 0){
		String path = application.getRealPath("fileUpload/winNum.txt");
		File f = new File(path);
		System.out.println(path);
		FileInputStream fis = new FileInputStream(f);
		byte[] buf = new byte[(int) f.length()];
		int size = -1;
		String contents = null;
		if ((size = fis.read(buf)) != -1) {
			contents = new String(buf, 0, size);
		}
		
		
		StringTokenizer st = new StringTokenizer(contents,"/");
		StringTokenizer in_st = null;
		WinNumVO vo = new WinNumVO();
		int cnt =0;
		boolean result = true;
		while (st.hasMoreTokens()) {
			String str = st.nextToken();
			if (!str.trim().equals("")) {
				in_st = new StringTokenizer(str,",");
				vo.setChapter(Integer.parseInt(in_st.nextToken().trim()));
				vo.setNum1(Integer.parseInt(in_st.nextToken().trim()));
				vo.setNum2(Integer.parseInt(in_st.nextToken().trim()));
				vo.setNum3(Integer.parseInt(in_st.nextToken().trim()));
				vo.setNum4(Integer.parseInt(in_st.nextToken().trim()));
				vo.setNum5(Integer.parseInt(in_st.nextToken().trim()));
				vo.setNum6(Integer.parseInt(in_st.nextToken().trim()));
				vo.setNum7(Integer.parseInt(in_st.nextToken().trim()));
				vo.setWin_date(in_st.nextToken());
				cnt =ss.insert("winNumAdd",vo);
				if(cnt != 1){
					result = false;
					break ;
				}
			}
		}
		
		if(result){
			ss.commit();
	//		response.sendRedirect("winNumPaging.jsp");
		}else{
		%>	
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<style type="text/css">
		div{
			border: 1px solid #dedede;
			text-align: center;
			width: 350px;
			height: 250px;
			
		}
	
	</style>
	</head>
	<body>
		<div>
				에러로 초기값을 인설트 못하였습니다 체크바람!
		</div>
	</body>
	</html>
			
		<%	
		}
	}else{
		
	//	response.sendRedirect("winNumPaging.jsp");
		
	}
		
		
		
	
%>